package com.woniuxy02;

import java.io.*;
import java.util.Arrays;

public class Test02 {
    public static void main(String[] args) throws IOException {
        System.out.println(Arrays.toString("abc中文字符".getBytes()));
        write();
        read();

    }

    private static void read() throws IOException {
        InputStreamReader is =
                new InputStreamReader(new FileInputStream("a.txt"),"gbk");
        int data;
//        //一次读取一个字符
//        while((data=is.read())!=-1){
//            System.out.println((char)data);
//        }
        //一次读取一个字符数组
        char[] chars = new char[2];
        int length;
        while ((length = is.read(chars)) != -1) {
            System.out.println(new String(chars,0,length));
        }
        is.close();
    }

    private static void write() throws IOException {
        OutputStreamWriter os =
                new OutputStreamWriter(new FileOutputStream("a.txt"),"gbk");
        os.write("abc中文字符");
        //字符流写入数据，调用flush()刷新
        os.flush();
        os.close();
    }
}
